/**
 * 
 */
package com.base.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.base.model.LoginUser;

/**
 * @author leiruiqi
 *
 */
public class LoginUtil {

	public static final ThreadLocal<Object> currentUser = new ThreadLocal<Object>();
	
	public static boolean validateCookie(HttpServletRequest req, HttpServletResponse res,String cookieName){
		boolean result = false;
		String value = CookieWrapper.getCookieValue(req, cookieName);
		if(value!=null){
			
			result = true;
			LoginUser user = new LoginUser();
			user.setName(value);
			setCurrentUser(user);
		}
		
		return result;
	}
	
	public static String getCookieValue(HttpServletRequest req, HttpServletResponse res,String cookieName){
		String value = CookieWrapper.getCookieValue(req, cookieName);
		return value;
	}
	
	
	
	public static void setCurrentUser(Object user){
		currentUser.set(user);
	}
	
	public static Object getCurrentUser(){
		return currentUser.get();
	}
	
}
